define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var product_category = {};
    var product_material = {};
    var product_purity = {};
    var product_technology = {};
    var product_skn = {};
    var supplier = {};
    $.ajax({
        url:"product/cate",
        async:false,
        success:function(res){
            product_category = res.product_category;
            product_material = res.product_material;
            product_purity = res.product_purity;
            product_technology = res.product_technology;
            product_skn = res.product_skn;
            supplier = res.supplier;
            console.log(supplier);
        }
    })
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'product/index' + location.search,
                    add_url: 'product/add',
                    edit_url: 'product/edit',
                    del_url: 'product/del',
                    multi_url: 'product/multi',
                    import_url: 'product/import',
                    table: 'product',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'supplier_id', title: __('Supplier_id'), searchList: supplier, formatter: function(res){
                            console.log(res);
                            if(supplier[res]){
                                return supplier[res];
                            }
                            
                        }},
                        {field: 'product_id', title: __('Product_id')},
                        {field: 'product_code', title: __('Product_code'), operate: 'LIKE'},
                        {field: 'product_name', title: __('Product_name'), operate: 'LIKE'},
                        {field: 'product_category', title: __('Product_category'),searchList: product_category, formatter: Table.api.formatter.nomal},
                        {field: 'product_material', title: __('Product_material'), searchList: product_material, formatter: Table.api.formatter.label,operate:'FIND_IN_SET'},
                        {field: 'product_purity', title: __('Product_purity'), searchList: product_purity, formatter: Table.api.formatter.label,operate:'FIND_IN_SET'},
                        {field: 'product_technology', title: __('Product_technology'), searchList: product_technology, formatter: Table.api.formatter.label,operate:'FIND_IN_SET'},
                        {field: 'product_skn', title: __('Product_skn'), searchList: product_skn, formatter: Table.api.formatter.label,operate:'FIND_IN_SET'},
                        {field: 'image_urls', title: __('Image_urls'),formatter: Table.api.formatter.images, operate: false},
                        {field: 'material_weight', title: __('Material_weight'), formatter: Table.api.formatter.label,operate:'FIND_IN_SET'},
                        {field: 'set.product_set_name', title: __('Set.product_set_name'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        index2: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'product/index2' + location.search,
                    add_url: 'product/add2',
                    edit_url: 'product/edit2',
                    del_url: 'product/del',
                    multi_url: 'product/multi',
                    import_url: 'product/import',
                    table: 'product',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'supplier_id', title: __('Supplier_id'), searchList: supplier, formatter: function(res){
                            console.log(res);
                            if(supplier[res]){
                                return supplier[res];
                            }
                            
                        }},
                        {field: 'product_id', title: __('Product_id')},
                        {field: 'product_code', title: __('Product_code'), operate: 'LIKE'},
                        {field: 'product_name', title: __('Product_name'), operate: 'LIKE'},
                        {field: 'product_category', title: __('Product_category'),searchList: product_category, formatter: Table.api.formatter.nomal},
                        {field: 'product_material', title: __('Product_material'), searchList: product_material, formatter: Table.api.formatter.label,operate:'FIND_IN_SET'},
                        {field: 'product_purity', title: __('Product_purity'), searchList: product_purity, formatter: Table.api.formatter.label,operate:'FIND_IN_SET'},
                        {field: 'product_technology', title: __('Product_technology'), searchList: product_technology, formatter: Table.api.formatter.label,operate:'FIND_IN_SET'},
                        {field: 'product_skn', title: __('Product_skn'), searchList: product_skn, formatter: Table.api.formatter.label,operate:'FIND_IN_SET'},
                        {field: 'image_urls', title: __('Image_urls'),formatter: Table.api.formatter.images, operate: false},
                        {field: 'material_weight', title: __('Material_weight'),formatter: Table.api.formatter.label,operate:'FIND_IN_SET'},
                        // {field: 'is_deleted', title: __('Is_deleted'), searchList: {"N":__('已删除'),"Y":__('未删除')}, formatter: Table.api.formatter.status},
                        {field: 'set.product_set_name', title: __('Set.product_set_name'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        add2: function () {
            Controller.api.bindevent();
        },
        edit2: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
